package com.jin.lazytool.handler;

import java.time.LocalDateTime;

public class TimeLoopHandler extends ILoopHandler{
    public TimeLoopHandler(){}
    private LocalDateTime dateTime;
    private Integer jumpCount;

    private TimeLoopHandler(LocalDateTime dateTime,Integer jumpCount){
        this.dateTime = dateTime;
        this.jumpCount = jumpCount;
    }

    @Override
    public Integer execute(Integer index) throws InterruptedException{
        if(this.dateTime.compareTo(LocalDateTime.now()) > 0){
            Thread.sleep(time);
            return index;
        }
        return index + jumpCount;
    }

    @Override
    public ILoopHandler newHandler(Integer count, long timer, LocalDateTime dateTime, String js,Integer jumpCount) {
        return new TimeLoopHandler(dateTime,jumpCount);
    }
}
